package com.dianxun.exam.adapter.provider;

import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.dianxun.exam.MainApplication;
import com.dianxun.exam.R;
import com.dianxun.exam.common.AppKeyManager;
import com.dianxun.exam.entity.ChoiceListBean;
import com.dianxun.exam.entity.ItemListBean;
import com.dianxun.exam.entity.TypeEntity;
import com.dianxun.exam.utils.Utils;

/**
 * 单选题
 */
public class SingleChoiceFinishProvider extends BaseItemProvider<TypeEntity, BaseViewHolder> {

    @Override
    public int viewType() {
        return AppKeyManager.TYPE_SINGLE_CHOICE;
    }

    @Override
    public int layout() {
        return R.layout.item_exam_single_choice;
    }

    @Override
    public void convert(BaseViewHolder helper, final TypeEntity data, int position) {
        ChoiceListBean entity = (ChoiceListBean) data;
        helper.setText(R.id.tv_title, (position - 1) + ".  " + entity.getItemName() + "（" + entity.getScore() + "分）");
        RadioGroup rg = helper.getView(R.id.rg_single);
        if (rg.getChildCount() == 0) {
            for (int i = 0; i < entity.getItemList().size(); i++) {
                final ItemListBean itemListBean = entity.getItemList().get(i);
                RadioButton radioButton = new RadioButton(mContext);
                radioButton.setClickable(false);
                RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT);
                layoutParams.setMargins(0, 10, 0, 0);
                radioButton.setLayoutParams(layoutParams);
                radioButton.setText(Utils.getNo(i) + itemListBean.getItemName());
                radioButton.setId(i);
                rg.addView(radioButton);
                if (itemListBean.getAnswer() == 1) {
                    rg.check(radioButton.getId());
                } else {
                    radioButton.setChecked(false);
                }
                if (itemListBean.getItemAnswer().equals("0")) {
                    radioButton.setTextColor(MainApplication.getInstance().getResources().getColor(R.color.black));
                } else {
                    radioButton.setTextColor(MainApplication.getInstance().getResources().getColor(R.color.red));
                }
            }
        }
    }

    @Override
    public void onClick(BaseViewHolder helper, TypeEntity data, int position) {

    }

    @Override
    public boolean onLongClick(BaseViewHolder helper, TypeEntity data, int position) {
        return true;
    }
}
